package com.ruoyi.web.controller.djb;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.djb.domain.DjbTag;
import com.ruoyi.djb.service.IDjbTagService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签管理Controller
 * 
 * @author xxd
 * @date 2023-12-08
 */
@Controller
@RequestMapping("/djb/tag")
public class DjbTagController extends BaseController
{
    private String prefix = "djb/tag";

    @Autowired
    private IDjbTagService djbTagService;

    @RequiresPermissions("djb:tag:view")
    @GetMapping()
    public String tag()
    {
        return prefix + "/tag";
    }

    /**
     * 查询标签管理列表
     */
    @RequiresPermissions("djb:tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbTag djbTag)
    {
        startPage();
        List<DjbTag> list = djbTagService.selectDjbTagList(djbTag);
        return getDataTable(list);
    }

    /**
     * 导出标签管理列表
     */
    @RequiresPermissions("djb:tag:export")
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbTag djbTag)
    {
        List<DjbTag> list = djbTagService.selectDjbTagList(djbTag);
        ExcelUtil<DjbTag> util = new ExcelUtil<DjbTag>(DjbTag.class);
        return util.exportExcel(list, "标签管理数据");
    }

    /**
     * 新增标签管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存标签管理
     */
    @RequiresPermissions("djb:tag:add")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbTag djbTag)
    {
        return toAjax(djbTagService.insertDjbTag(djbTag));
    }

    /**
     * 修改标签管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbTag djbTag = djbTagService.selectDjbTagById(id);
        mmap.put("djbTag", djbTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存标签管理
     */
    @RequiresPermissions("djb:tag:edit")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbTag djbTag)
    {
        return toAjax(djbTagService.updateDjbTag(djbTag));
    }

    /**
     * 删除标签管理
     */
    @RequiresPermissions("djb:tag:remove")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbTagService.deleteDjbTagByIds(ids));
    }
}
